import request from '@/utils/request'
import { getToken } from '@/utils/auth'

export function login (data) {
  return request({
    url: '/api/login',
    method: 'post',
    data
  })
}

export function register (data) {
  return request({
    url: '/api/reg',
    method: 'post',
    data
  })
}

export function getUserinfo () {
  return request({
    url: '/my/userinfo',
    method: 'GET',
    headers: {
      Authorization: `${getToken()}`
    }
  })
}

export function setUserinfo (data) {
  return request({
    url: '/my/userinfo',
    method: 'PUT',
    headers: {
      Authorization: `${getToken()}`
    },
    data
  })
}

export function setAvatar (data) {
  return request({
    url: '/my/update/avatar',
    method: 'PATCH',
    headers: {
      Authorization: `${getToken()}`
    },
    data
  })
}

export function setPwd (data) {
  return request({
    url: '/my/updatepwd',
    method: 'PATCH',
    headers: {
      Authorization: `${getToken()}`
    },
    data
  })
}
